function userNameinit(){
    //username检验置空
    document.getElementById("userName").addEventListener("focus",()=>{
        document.querySelector(".userName_error_msg").innerHTML="";
        document.querySelector(".userName_error_img").classList.remove("errorImg");
        document.querySelector(".userName_error_msg").classList.remove("errorMessage");
        document.querySelector(".userName_error_msg").classList.remove("okMessage");
        document.querySelector(".userName_error_img").classList.remove("okImg");
    },false);
    //username检验
    document.getElementById("userName").addEventListener("blur",()=>{
        let regExp=/^[a-zA-Z0-9_.-]+$/;
        if(!regExp.test(document.getElementById("userName").value)){
            document.querySelector(".userName_error_msg").innerHTML="格式不正确！";
            document.querySelector(".userName_error_msg").classList.add("errorMessage");
            document.querySelector(".userName_error_img").classList.add("errorImg");
        }else{
            document.querySelector(".userName_error_msg").innerHTML="格式符合要求！";
            document.querySelector(".userName_error_msg").classList.add("okMessage");
            document.querySelector(".userName_error_img").classList.add("okImg");
            
        }
    },false);
}

function phoneinit(){
    //username检验置空
    document.getElementById("phone").addEventListener("focus",()=>{
        document.querySelector(".phone_error_msg").innerHTML="";
        document.querySelector(".phone_error_img").classList.remove("errorImg");
        document.querySelector(".phone_error_msg").classList.remove("errorMessage");
        document.querySelector(".phone_error_msg").classList.remove("okMessage");
        document.querySelector(".phone_error_img").classList.remove("okImg");
    },false);
    //phone检验
    document.getElementById("phone").addEventListener("blur",()=>{
        let regExp=/^[0-9_.-]+$/;
        if(!regExp.test(document.getElementById("phone").value)){
            document.querySelector(".phone_error_msg").innerHTML="格式不正确！";
            document.querySelector(".phone_error_msg").classList.add("errorMessage");
            document.querySelector(".phone_error_img").classList.add("errorImg");
        }else{
            document.querySelector(".phone_error_msg").innerHTML="格式符合要求！";
            document.querySelector(".phone_error_msg").classList.add("okMessage");
            document.querySelector(".phone_error_img").classList.add("okImg");
            
        }
    },false);
}


function emailinit(){
    //email检验置空
    document.getElementById("email").addEventListener("focus",()=>{
        document.querySelector(".email_error_msg").innerHTML="";
        document.querySelector(".email_error_img").classList.remove("errorImg");
        document.querySelector(".email_error_msg").classList.remove("errorMessage");
        document.querySelector(".email_error_msg").classList.remove("okMessage");
        document.querySelector(".email_error_img").classList.remove("okImg");
    },false);
    //email检验
    document.getElementById("email").addEventListener("blur",()=>{
        let regExp=/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
        if(!regExp.test(document.getElementById("email").value)){
            document.querySelector(".email_error_msg").innerHTML="邮箱格式不正确！";
            document.querySelector(".email_error_msg").classList.add("errorMessage");
            document.querySelector(".email_error_img").classList.add("errorImg");
        }else{
            document.querySelector(".email_error_msg").innerHTML="邮箱格式符合要求！";
            document.querySelector(".email_error_msg").classList.add("okMessage");
            document.querySelector(".email_error_img").classList.add("okImg");
            
        }
    },false);
}

function nickNameinit(){
    //检验置空
    document.getElementById("nickName").addEventListener("focus",()=>{
        document.querySelector(".nickName_error_msg").innerHTML="";
        document.querySelector(".nickName_error_img").classList.remove("errorImg");
        document.querySelector(".nickName_error_msg").classList.remove("errorMessage");
        document.querySelector(".nickName_error_msg").classList.remove("okMessage");
        document.querySelector(".nickName_error_img").classList.remove("okImg");
    },false);
    //检验
    document.getElementById("nickName").addEventListener("blur",()=>{
        let regExp=/^[a-zA-Z0-9_.-]+$/;
        if(!regExp.test(document.getElementById("nickName").value)){
            document.querySelector(".nickName_error_msg").innerHTML="输入格式不正确！";
            document.querySelector(".nickName_error_msg").classList.add("errorMessage");
            document.querySelector(".nickName_error_img").classList.add("errorImg");
        }else{
            document.querySelector(".nickName_error_msg").innerHTML="输入格式符合要求！";
            document.querySelector(".nickName_error_msg").classList.add("okMessage");
            document.querySelector(".nickName_error_img").classList.add("okImg");
        }
    },false);
}


function passwordinit(){
    //检验置空
    document.getElementById("password").addEventListener("focus",()=>{
        document.querySelector(".password_error_msg").innerHTML="";
        document.querySelector(".password_error_img").classList.remove("errorImg");
        document.querySelector(".password_error_msg").classList.remove("errorMessage");
        document.querySelector(".password_error_msg").classList.remove("okMessage");
        document.querySelector(".password_error_img").classList.remove("okImg");
    },false);
    //检验
    document.getElementById("password").addEventListener("blur",()=>{
        let regExp=/^[a-zA-Z0-9_.-]+$/;
        if(!regExp.test(document.getElementById("password").value)){
            document.querySelector(".password_error_msg").innerHTML="输入格式不正确！";
            document.querySelector(".password_error_msg").classList.add("errorMessage");
            document.querySelector(".password_error_img").classList.add("errorImg");
        }else{
            document.querySelector(".password_error_msg").innerHTML="输入格式符合要求！";
            document.querySelector(".password_error_msg").classList.add("okMessage");
            document.querySelector(".password_error_img").classList.add("okImg");
        }
    },false);
}




function repasswordinit(){
    //检验置空
    document.getElementById("repassword").addEventListener("focus",()=>{
        document.querySelector(".repassword_error_msg").innerHTML=" ";
        document.querySelector(".repassword_error_img").classList.remove("errorImg");
        document.querySelector(".repassword_error_msg").classList.remove("errorMessage");
        document.querySelector(".repassword_error_msg").classList.remove("okMessage");
        document.querySelector(".repassword_error_img").classList.remove("okImg");
    },false);
    //检验
    document.getElementById("repassword").addEventListener("blur",()=>{
        let regExp=/^[a-zA-Z0-9_.-]+$/;
        var pwd1 = document.getElementById("password").value;
        var pwd2 = document.getElementById("repassword").value;    
        if(pwd1==pwd2){
            document.querySelector(".repassword_error_msg").innerHTML="前后密码一致";
            document.querySelector(".repassword_error_msg").classList.add("okMessage");
            document.querySelector(".repassword_error_img").classList.add("okImg");
        }else{
            document.querySelector(".repassword_error_msg").innerHTML="前后密码不一致！";    
            document.querySelector(".repassword_error_msg").classList.add("errorMessage");
            document.querySelector(".repassword_error_img").classList.add("errorImg");
        
        }
    },false);
}





function IsNull(){ 
    var str = document.getElementById("password").value.trim(); 
    if(str.length==0){ 
    alert('对不起，输入内容不能为空或者为空格!');//请将“文本框”改成你需要验证的属性名称! 
    }
} 

window.addEventListener("load",emailinit,false);

window.addEventListener("load",nickNameinit,false);

window.addEventListener("load",passwordinit,false);

window.addEventListener("load",repasswordinit,false);

window.addEventListener("load",userNameinit,false);

window.addEventListener("load",phoneinit,false);